package com.fzf.blog.modules.api.controller;


import com.fzf.blog.core.annotation.AccessLimit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fzf.blog.modules.admin.model.Menu;
import com.fzf.blog.modules.admin.service.MenuService;

import java.util.*;

/**
 * 类别
 *
 * @author fzf
 */
@CrossOrigin
@RestController
@RequestMapping("/blog")
public class MenuController {

    @Autowired
    private MenuService menuService;


    @GetMapping("/menu")
    @AccessLimit(seconds=1,maxCount=15)
    public List<Map<String, String>> menuList() {
        List<Menu> menus = menuService.selectAll();
        menus.sort(Comparator.comparing(Menu::getSequence));
        List<Map<String, String>> cates = new ArrayList<>();
        for (Menu menu : menus) {
            Map<String, String> cateMap = new HashMap<>(2);
            cateMap.put("name", menu.getName());
            cateMap.put("url", menu.getUrl());
            cates.add(cateMap);
        }
        return cates;
    }
}
